package net.xiduth.game.player.dialogues.impl;

import net.xiduth.game.player.content.grandexchange.GrandExchangeOffer;
import net.xiduth.game.player.content.grandexchange.WorldOffers;
import net.xiduth.game.player.dialogues.Dialogue;
import net.xiduth.utils.ChatColors;
import net.xiduth.utils.Misc;

/**
 * @author Tyluur <itstyluur@gmail.com>
 * @since 2012-08-17
 */
public class ExchangeClerk extends Dialogue {

	int npcId;

	@Override
	public void start() {
		npcId = (Integer) parameters[0];
		sendPlayerDialogue(NO_EXPRESSION, "Hi there.");
	}

	@Override
	public void run(int interfaceId, int option) {
		switch(stage) {
		case -1:
			sendNPCDialogue(npcId, NO_EXPRESSION, "Good afternoon, "
					+ (player.getAppearence().isMale() ? "sir" : "lady")
					+ ". How may I help you?");
			stage = 0;
			break;
		case 0:
			sendOptionsDialogue("Select an option", "I want to access the grand exchange, please.", "Can I see the available offers?");
			stage = 1;
			break;
		case 1:
			switch(option) {
			case OPTION_1:
				sendPlayerDialogue(NO_EXPRESSION, "I want to access the grand exchange, please.");
				stage = 2;
				break;
			case OPTION_2:
				player.getInterfaceManager().closeScreenInterface();
				for (int i = 0; i < 295; i++) {
					player.getPackets().sendIComponentText(275, i, "");
				}
				player.getPackets().sendIComponentText(275, 1, "<col=" + ChatColors.WHITE + ">Grand Exchange Offers");
				player.getPackets().sendIComponentText(275, 10, "[Amount Purchasing/Amount Completed]");
				player.getInterfaceManager().sendInterface(275);
				int number = 12;
				for (GrandExchangeOffer offers : WorldOffers.getOffers()) {
					if (offers == null || offers.getOwner() == null) continue;
					player.getPackets().sendIComponentText(275, number, "<col="+ ChatColors.PURPLE + ">The user '" + Misc.formatPlayerNameForDisplay(offers.getOwner().getUsername()) + "' is " + offers.getType().name().toLowerCase() + "ing " + offers.getOfferedAmount() + "x " + offers.getItem().getName() + "</col>[<col=" + ChatColors.MILD_BLUE + ">" + offers.getOfferedAmount() + "</col>/<col=" + ChatColors.MILD_BLUE + ">" + offers.getAmountCompleted() + "</col>]");
					number++;
				}
				break;
			case OPTION_3:
			case OPTION_4:
			case OPTION_5:
				end();
				break;
			}
			break;
		case 2:
			sendNPCDialogue(npcId, GOOFY_LAUGH, "Of course! Have fun.");
			stage = 3;
			break;
		case 3:
			end();
			player.getGrandExchange().sendExchangeScreen();
			break;
		}
	}

	@Override
	public void finish() {

	}

}
